#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPainter>
#include "mypushbutton.h"
#include<QDebug>
#include<QTimer>
#include<QSound>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setFixedSize(320,588);
    setWindowIcon(QIcon(":/res/Coin0001.png"));
    setWindowTitle("反金币");
    connect(ui->actionquit,&QAction::triggered,[=](){
        this->close();
    });

    QSound * game = new QSound(":/res/LevelWinSound.wav",this);
    QSound * startSound = new QSound(":/res/TapButtonSound.wav",this);
    game->setLoops(-1);
    game->play();
    MypushButton * startBtn = new MypushButton(":/res/MenuSceneStartButton.png");
    startBtn->setParent(this);
    startBtn->move(this->width() * 0.5 -startBtn->width()*0.5,this->height() * 0.7);

    choo = new Choose;
    connect(choo,&Choose::Choosebackbutton,[=](){
        choo->hide();
        this->show();
    });

    connect(startBtn,&MypushButton::clicked,[=](){
        qDebug()<<"点了下开始";

        startSound->play();
        startBtn->zoom2();

        QTimer::singleShot(500,this,[=](){
                           this->hide();
                           choo->show();
        });


    });







}

MainWindow::~MainWindow()
{
    delete ui;
}



void MainWindow::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);

    //加载图片
    pix.load(":/res/Title.png");
       //绘制背景图
    pix =pix.scaled(pix.width()*0.5,pix.height()*0.5);
    painter.drawPixmap(10,30,pix);
}

